package com.frank.biz.project.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.frank.common.annotation.Log;
import com.frank.common.enums.BusinessType;
import com.frank.biz.project.domain.BizProject;
import com.frank.biz.project.service.IBizProjectService;
import com.frank.common.core.controller.BaseController;
import com.frank.common.core.domain.AjaxResult;
import com.frank.common.utils.poi.ExcelUtil;
import com.frank.common.core.page.TableDataInfo;

/**
 * 汇报信息Controller
 * 
 * @author frank
 * @date 2024-09-10
 */
@Controller
@RequestMapping("/biz/project")
public class BizProjectController extends BaseController
{
    private String prefix = "biz/project";

    @Autowired
    private IBizProjectService bizProjectService;

    @RequiresPermissions("biz:project:view")
    @GetMapping()
    public String project()
    {
        return prefix + "/project";
    }

    /**
     * 查询汇报信息列表
     */
    @RequiresPermissions("biz:project:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizProject bizProject)
    {
        startPage();
        bizProject.setCreateBy(getLoginName());
        List<BizProject> list = bizProjectService.selectBizProjectList(bizProject);
        return getDataTable(list);
    }

    /**
     * 导出汇报信息列表
     */
    @RequiresPermissions("biz:project:export")
    @Log(title = "汇报信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizProject bizProject)
    {
        bizProject.setCreateBy(getLoginName());
        List<BizProject> list = bizProjectService.selectBizProjectList(bizProject);
        ExcelUtil<BizProject> util = new ExcelUtil<BizProject>(BizProject.class);
        return util.exportExcel(list, "汇报信息数据");
    }

    /**
     * 新增汇报信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存汇报信息
     */
    @RequiresPermissions("biz:project:add")
    @Log(title = "汇报信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizProject bizProject)
    {
        bizProject.setCreateBy(getLoginName());
        return toAjax(bizProjectService.insertBizProject(bizProject));
    }

    /**
     * 修改汇报信息
     */
    @RequiresPermissions("biz:project:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BizProject bizProject = bizProjectService.selectBizProjectById(id);
        mmap.put("bizProject", bizProject);
        return prefix + "/edit";
    }

    /**
     * 修改保存汇报信息
     */
    @RequiresPermissions("biz:project:edit")
    @Log(title = "汇报信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizProject bizProject)
    {
        bizProject.setUpdateBy(getLoginName());
        return toAjax(bizProjectService.updateBizProject(bizProject));
    }

    /**
     * 删除汇报信息
     */
    @RequiresPermissions("biz:project:remove")
    @Log(title = "汇报信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bizProjectService.deleteBizProjectByIds(ids));
    }
}
